<%- partial('../course_sidebar') %>


<div id="content">
  <h1><%- course.name %></h1>
  <p>Teacher:<%- course.teacher_name %></p>
  <div class="panel">
    <div class="header">
      <% [['all', '全部'], ['good', '精华']].concat(tabs).forEach(function (pair) {
        var value = pair[0];
        var text = pair[1]; %>
        <a href="/course/<%= value ? cid+'/?tab=' + value : '/' %>"
          class="topic-tab <%= value === tab ? 'current-tab' : '' %>"><%= text %></a>
      <% }) %>

      <div class = "action">
        <% if (course.collect_user.indexOf(user._id) >= 0) { %>
          <span class="span-common" id = "coursecollect"action="collect">
            booking
          </span>
        <% }  else { console.log(course.collect_user.indexOf(user._id))%>
          <span class="span-common span-success" id = "coursecollect"action="collect">
            book
          </span>
        <% } %>
      </div>

    </div>
    <div class="panel">
      <div class='inner'>
        <a href='/topic/create/<%- course._id %>' id='create_topic_btn'>
          <span class='span-success'>发布新话题</span>
        </a>
      </div>
    </div>
    <% if (typeof(topics) !== 'undefined' && topics.length > 0) { %>
    <div class="inner no-padding">
      <%- partial('../topic/list', {
      topics: topics,
      pages: pages,
      current_page: current_page,
      base: '/course/' + cid + '/'
      }) %>
    </div>
    <% } else { %>
    <div class="inner">
      <p>无话题</p>
    </div>
    <% } %>
  </div>
</div>

<script>
$('#coursecollect').click(function () {
      var $me = $(this);
      this.innerHTML = "booking";
      this.className = "span-common";
      var action = $me.attr('action');
      var data = {
        course_id: '<%= cid%>',
        _csrf: ''
      };
      $.post('/course/' + action, data, function (data) {
        if (data.status === 'success') {
          if (action == 'collect') {
            $me.attr('action', 'collect');
          } else {
            $me.attr('action', 'collect');
          }
          $me.toggleClass('span-success');
        }
      }, 'json');
    });
</script>

